package com.teach.controller.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.teach.R;
import com.teach.config.ConfigProperties;
import com.teach.service.FileService;

/**
 * <pre>
 * 文件上传测试
 * 创建时间 ：	2019年12月11日 下午3:17:23
 * 当前版本：	V1.0
 * Copyright © 1998 - 2019 jlzhou.top. All Rights Reserved	
 * </pre>
 * @author J.L.Zhou
 *
 */
@RestController
@RequestMapping("/demo")
public class DemoUploadController {

	@Autowired
	private FileService service;
	
	@Autowired
	private ConfigProperties config;
	
	@PostMapping("upload.do")
	public R doUpload(MultipartFile file,Integer type) {
		if(!config.dev) {
			return R.ok();
		}
		switch (type) {
		case 1:
			return R.ok().put("url", service.save(file,true));
		case 2:
			return R.ok().put("url", service.saveImage(file));
		case 3:
			return R.ok().put("url", service.saveThumbnail(file));
		default:
			return R.ok().put("url", service.save(file));
		}
		
	}
}
